<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/7/1
 * Time: 23:22
 */

namespace App;

class Emoji {

    static $map = ["/::)", "/::~", "/::B", "/::|", "/:8-)", "/::<", "/::$", "/::X", "/::Z",
        "/::'(", "/::-|", "/::@", "/::P", "/::D", "/::O", "/::(", "/::+", "/:--b", "/::Q",
        "/::T", "/:,@P", "/:,@-D", "/::d", "/:,@o", "/::g", "/:|-)", "/::!", "/::L",
        "/::>", "/::,@", "/:,@f", "/::-S", "/:?", "/:,@x", "/:,@@", "/::8", "/:,@!",
        "/:!!!", "/:xx", "/:bye", "/:wipe", "/:dig", "/:handclap",
        "/:&-(", "/:B-)", "/:<@", "/:@>", "/::-O", "/:>-|", "/:P-(",
        "/::'|", "/:X-)", "/::*", "/:@x", "/:8*", "/:pd", "/:",
        "/:beer", "/:basketb", "/:oo", "/:coffee", "/:eat", "/:pig",
        "/:rose", "/:fade", "/:showlove", "/:heart", "/:break", "/:cake", "/:li",
        "/:bome", "/:kn", "/:footb", "/:ladybug", "/:shit", "/:moon", "/:sun", "/:gift", "/:hug", "/:strong",
        "/:weak", "/:share", "/:v", "/:@)", "/:jj", "/:@@", "/:bad", "/:lvu", "/:no", "/:ok", "/:love", "/:",
        "/:jump", "/:shake", "/:", "/:circle", "/:kotow", "/:turn", "/:skip", "/:oY", "/:#-0", "/:hiphot",
        "/:kiss", "/:<&", "/:&>"];

    static function render($content)
    {
        foreach (self::$map as $k => $v) {
            $content = str_replace($k, '<img src="data:image/gif;base64,'.$v.'" alt="">', $content);
        }
        return $content;
    }

    public static function randomEmoji($tag, $content)
    {
        $tag = str_replace("{", "\{", $tag);
        $tag = str_replace("}", "\}", $tag);
        $tag = "/" . $tag. "/";
        $match = [];
        $count = preg_match_all($tag, $content, $match);
        for ($i = 0 ;$i<$count;$i++) {
            $content = preg_replace($tag, self::$map[rand(0, count(self::$map) - 1)], $content, 1);
        }
        return $content;
    }

}